﻿using System.Collections.Generic;
using System.Linq;
using GP.Scripts.City;
using Gp.Scripts.Data;
using QFramework;
using UnityEngine;
using Random = UnityEngine.Random;

namespace Gp.Scripts.Core {
    public class CreatureSpawner : MonoBehaviour,IController {
        public List<CreatureConfig> configs = new List<CreatureConfig>();
        
        public List<SpawnPlace> places = new List<SpawnPlace>();
        
        private List<SpawnPlace> ordinalPlaces = new List<SpawnPlace>();
        
        private List<SpawnPlace> availablePlaces = new List<SpawnPlace>();
        
        public int spawnNumber = 0;
        
        private void Start() {
            // Global.Get<SpawnSystem>().ChangeSpawner(this);
            // foreach (var spawnPlace in places.Where(spawnPlace => !spawnPlace.isSpecial)) {
            //     ordinalPlaces.Add(spawnPlace);
            //     availablePlaces.Add(spawnPlace);
            // }
            //
            // for (int i = 0; i < spawnNumber; i++) {
            //     if (availablePlaces.Count == 0) {
            //         return;
            //     }
            //     SpawnCreature();
            // }
        }
        
        
        public void SpawnCreature() {
            var pIndex = Random.Range(0, availablePlaces.Count);
            var cIndex = Random.Range(0, configs.Count);
            Debug.Log(availablePlaces.Count + " " + configs.Count);
            Debug.Log(pIndex + " " + cIndex);
            availablePlaces[pIndex].SpawnCreature(configs[cIndex]);
            availablePlaces.RemoveAt(pIndex);
        }
        public IArchitecture GetArchitecture() {
            return SceneScriptArchitecture.Interface;
        }
    }
}